package com.gitee.smsdistribution.controller;

import com.gitee.smsdistribution.common_response.ResponseResultBody;
import com.gitee.smsdistribution.model.DistributionPolicy;
import com.gitee.smsdistribution.service.DistributionPolicyService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@ResponseResultBody
@AllArgsConstructor
@RestController
@RequestMapping("/distribution-policy")
public class DistributionPolicyController {
    private final DistributionPolicyService distributionPolicyService;


    @GetMapping("/search")
    public Page<DistributionPolicy> searchByKeyword(@RequestParam String keyword,
                                                    @RequestParam(defaultValue = "0") int page,
                                                    @RequestParam(defaultValue = "10") int size) {
        return distributionPolicyService.searchByKeyword(keyword, page, size);
    }

    @PostMapping
    public void insertBatch(@RequestBody List<DistributionPolicy> policies) {
        distributionPolicyService.insertBatch(policies);
    }
}
